using System;
using System.Collections.Generic;
using Plain.Demo.Blog.Business;

namespace Plain.Demo.Blog.Web
{
	public static class PostExtensions
	{
		public static Feed ToFeed(this IList<Post> posts, string title, string url, string itemUrl, string description, string language)
        {
			IList<FeedItem> feedItems = new List<FeedItem>();
            foreach(Post post in posts){
				FeedItem feedItem = new FeedItem() { Title = post.Title, Url = itemUrl + "/" + post.Id, Description = post.Content, Author = post.Author.Email, Tags = post.Tags, Published = post.Published.Value };
				feedItems.Add(feedItem);
			}
			Feed feed = new Feed(feedItems);
			feed.Title = title;
			feed.Url = url;
			feed.Description = description;
			feed.Language = language;
			
			return feed;
        }
	}
}